package com.testdemo.web.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.testdemo.web.dao.ManagerDao;
import com.testdemo.web.vo.Group;
import com.testdemo.web.vo.MyUser;
import com.testdemo.web.vo.UserInfo;

@Service
public class ManagerImpl implements Manager {

	@Autowired
	private ManagerDao managerDao;
	
	@Override
	public List<UserInfo> getAllUserInfoInLabOrGroup(Integer labid, Integer groupid) {
		if(groupid == -1) {
			return managerDao.selectUserByLabId(labid);
		}else {
			return managerDao.selectUserByGroupId(groupid);
		}
		
	}

	@Override
	public List<MyUser> getApplyInLabByLabid(Integer labid) {
		return managerDao.selectMyUserApplyByLabid(labid);
	}

	@Override
	public int checkApplyInLab(MyUser user) {
		if(user.getLevel() == 0) {
			return managerDao.deleteMyUserByUserName(user.getUsername());
		}else {
			return managerDao.updateMyUserByUserName(user.getUsername());
		}
		
	}

	@Override
	public int devideUserInToGroup(Group group) {
		return managerDao.updateUserInfoGroupIdByGroup(group);
	}


}
